package com.hllxd.hism.passport.base.util;

import com.alibaba.fastjson.JSONObject;
import com.hllxd.hism.passport.base.error.ErrorCode;

/**
 * Created by geran on 16/10/31.
 */
public class PassportUtil {

    public static String generateResultManually(String code, String message, Boolean success, Object
            data) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", code);
        jsonObject.put("message", message);
        jsonObject.put("success", success);
        jsonObject.put("data", data);
        return jsonObject.toJSONString();
    }

    public static String generateResultFromPassportError(ErrorCode errorCode, Object
            data) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", errorCode.getCode());
        jsonObject.put("message", errorCode.getMessage());
        jsonObject.put("success", errorCode.isSuccess());
        jsonObject.put("data", data);
        return jsonObject.toJSONString();
    }

    public static String generateResult(ErrorCode errorCode) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", errorCode.getCode());
        jsonObject.put("message", errorCode.getMessage());
        jsonObject.put("success", errorCode.isSuccess());
        return jsonObject.toJSONString();
    }

}
